<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video
          controls
          :src="url"
        ></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="icon" alt="" />
          </div>
          <span class="name">{{mvMessages.artistName}}</span>
        </div>
        <div class="mv-info">
          <h2 class="title">{{mvMessages.name}}</h2>
          <span class="date">发布：{{mvMessages.publishTime}}</span>
          <span class="number">播放：{{mvMessages.playCount}}次</span>
          <p class="desc">
            {{mvMessages.desc}}
          </p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap">
        <p class="title">精彩评论<span class="number">({{hotCount}})</span></p>
        <div class="comments-wrap">
          <div v-for="(hotComment, index) in hotComments" :key="index" class="item">
            <div class="icon-wrap">
              <img :src="hotComment.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{hotComment.user.nickname}}:</span>
                <span class="comment">{{hotComment.content}}</span>
              </div>
              <div class="re-content" v-if="hotComment.beReplied.length" >
                <span class="name">{{hotComment.beReplied[0].user.nickname}}:</span>
                <span class="comment">{{hotComment.beReplied[0].content}}</span>
              </div>
              <div class="date">2020-02-12 17:26:11</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">最新评论<span class="number">({{Count}})</span></p>
        <div class="comments-wrap">
          <div v-for="(comment, index) in comments" :key="index" class="item">
            <div class="icon-wrap">
              <img :src="comment.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div  class="content">
                <span class="name">{{comment.user.nickname}}:</span>
                <span class="comment">{{comment.content}}</span>
              </div>
              <div class="re-content" v-if="comment.beReplied.length">
                <span class="name">{{comment.beReplied[0].user.nickname}}:</span>
                <span class="comment">{{comment.beReplied[0].content}}</span>
              </div>
              <div class="date">2020-02-12 17:26:11</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="5"
        :limit="limit"
      >
      </el-pagination>
    </div>
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item" @click="toMv(aboutMv.id)" v-for="(aboutMv, index) in aboutMvs" :key="index">
            <div class="img-wrap">
              <img :src="aboutMv.cover" alt="" />
              <span class="iconfont icon-play"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{aboutMv.playCount}}</div>
              </div>
              <span class="time">{{aboutMv.duration | date-format}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{aboutMv.name}}</div>
              <div class="singer">{{aboutMv.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'mv',
  data() {
    return {
      // 总条数
      total: 20,
      // 页码
      page: 1,
      // 页容量
      limit: 10,
      // 获取mv地址
      url:'',
      // 获取相关推荐
      aboutMvs:[],
      // 获取mv信息
      mvMessages:{},
      // 歌手头像
      icon:'',
      // 热门评论
      hotComments:[],
      // 最新评论
      comments:[],
      // 热门评论的个数
      hotCount:0,
      // 最新评论的个数
      Count:0,
    };
  },
  created() {
    // mv详情
    axios({
      url:'https://autumnfish.cn/mv/url',
      method:'get',
      params:{
        id:this.$route.query.name,
      }
    }).then(res=>{
      // console.log(res);
      this.url = res.data.data.url
    })
    // 相关推荐
    axios({
      url:'https://autumnfish.cn/simi/mv',
      method:'get',
      params:{
        mvid:this.$route.query.name,
      }
    }).then(res=>{
      // console.log(res);
      this.aboutMvs = res.data.mvs
    })
    // mv信息
    axios({
    url:'https://autumnfish.cn/mv/detail',
    method:'get',
    params:{
      mvid:this.$route.query.name,
    }
  }).then(res=>{
    // console.log(res);
    this.mvMessages = res.data.data
    // 获取歌手信息
    axios({
    url:'https://autumnfish.cn/artists',
    method:'get',
    params:{
      id:this.mvMessages.artists[0].id
    }
  }).then(res=>{
    // console.log(res);
    // 歌手的封面信息
    this.icon = res.data.artist.picUrl
  })
  })
    axios({
      url:'https://autumnfish.cn/comment/mv',
      method:'get',
      params:{
        id:this.$route.query.name,
        limit:10,
        offset:0
      }
    }).then(res=>{
      console.log(res);
      // 精彩评论
      this.hotComments = res.data.hotComments
      // 保存个数
      this.hotCount = res.data.total
      // 最新评论
       this.comments = res.data.comments
        // 最新评论个数
      this.Count = res.data.total
    })
  },
  methods: {
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page = val;
      axios({
      url:'https://autumnfish.cn/comment/mv',
      method:'get',
      params:{
        id:this.$route.query.name,
        limit:10,
        offset:(this.page-1)*10
      }
    }).then(res=>{
      console.log(res);
      // 精彩评论
      this.hotComments = res.data.hotComments
      // 保存个数
      this.hotCount = res.data.total
      // 最新评论
       this.comments = res.data.comments
        // 最新评论个数
      this.Count = res.data.total
    })
    },
    // 播放相关推荐中的mv
    toMv(id){
      // mv详情
      axios({
        url:'https://autumnfish.cn/mv/url',
        method:'get',
        params:{
          id
        }
      }).then(res=>{
        // console.log(res);
        this.url = res.data.data.url
      })
      // 相关推荐
      axios({
        url:'https://autumnfish.cn/simi/mv',
        method:'get',
        params:{
          mvid:id,
        }
      }).then(res=>{
        // console.log(res);
        this.aboutMvs = res.data.mvs
      })
      // mv信息
      axios({
      url:'https://autumnfish.cn/mv/detail',
      method:'get',
      params:{
        mvid:id,
      }
    }).then(res=>{
      // console.log(res);
      this.mvMessages = res.data.data
      // 获取歌手信息
      axios({
      url:'https://autumnfish.cn/artists',
      method:'get',
      params:{
        id:this.mvMessages.artists[0].id
      }
    }).then(res=>{
      // console.log(res);
      // 歌手的封面信息
      this.icon = res.data.artist.picUrl
    })
    })
      axios({
        url:'https://autumnfish.cn/comment/mv',
        method:'get',
        params:{
          id,
          limit:10,
          offset:0
        }
      }).then(res=>{
        // console.log(res);
        // 精彩评论
        this.hotComments = res.data.hotComments
        // 保存个数
        this.hotCount = res.data.total
        // 最新评论
        this.comments = res.data.comments
          // 最新评论个数
        this.Count = res.data.total
      })
      
  }
}
}
</script>

<style></style>
